package com.kgcx.organization.rabbitmq.consumer;

import com.alibaba.fastjson.JSONObject;
import com.kgcx.common.rabbitmq.consts.QueueConst;
import com.kgcx.organization.domain.CustomerMsg;
import com.kgcx.organization.service.CustomerMsgService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 订单取消时状态变更
 */
@Component
public class CustomerMsgSendConsumer {
    private static final Logger LOG = LoggerFactory.getLogger(CustomerMsgSendConsumer.class);

    @Autowired
    private CustomerMsgService customerMsgService;

    @RabbitListener(queues = QueueConst.CUSTOMER_MSG_SEND, errorHandler = "custRabbitListenerErrorHandler")
    @Transactional(rollbackFor = Exception.class)
    public void sendCustomerMsg(String json) {
        LOG.info("收到订单取消的MQ消息。\n" + json);

        CustomerMsg customerMsg = JSONObject.parseObject(json, CustomerMsg.class);
        customerMsgService.addCustomerMsg(customerMsg);

    }


}
